/*
 * $Id: LocationImportTemplateController.java 46 2013-05-03 21:38:12Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 46 $
 * $Date: 2013-05-03 21:38:12 +0000 (Fri, 03 May 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.web.controller.admin;

import com.sci.logisticsmap.service.LocationImportTemplateService;
import com.sci.logisticsmap.service.model.LocationImportTemplateLightDTModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * The Controller for processing Location import template admin view/ajax requests.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 46 $
 */
@Controller("admin.LocationImportTemplateController")
@RequestMapping("")
public class LocationImportTemplateController extends BaseController {
    /**
     * The Location import template admin path.
     */
    public static final String PATH_ADMIN_LOCATION_IMPORT_TEMPLATE = "/admin/location-import-template";
    /**
     * The Location import template list admin path.
     */
    public static final String PATH_ADMIN_LOCATION_IMPORT_TEMPLATE_LIST = "/admin/location-import-template/list";

    /**
     * The Location import template list admin view.
     */
    private final String viewList = "admin/locationImportTemplate/listPage";

    /**
     * The Location import template service.
     */
    @Autowired
    private LocationImportTemplateService locationImportTemplateService;

    /**
     * The default constructor.
     * Initializes a Controller class.
     */
    public LocationImportTemplateController() {
    }

    /*
     * (non-Javadoc)
     *
     * @see BaseController#init()
     */
    @PostConstruct
    public void init() {
        super.init();
    }

    /**
     * The method to response on the Location import template list admin view request.
     *
     * @param  model
     *         The model.
     *
     * @return the Location import template list admin view.
     */
    @RequestMapping(value={PATH_ADMIN_LOCATION_IMPORT_TEMPLATE, PATH_ADMIN_LOCATION_IMPORT_TEMPLATE_LIST}, method={RequestMethod.GET})
    public String onList(Model model) {
        try {
            List<LocationImportTemplateLightDTModel> locationImportTemplates = locationImportTemplateService.getLightDTModels();
            model.addAttribute("locationImportTemplateList", locationImportTemplates);
        } catch (Exception e) {
            addExceptionToModel(model, e);
        }

        return viewList;
    }
}
